package view
{
	import flash.events.Event;
	import flash.geom.Point;
	
	import interfaces.IView;
	
	import manager.BulletName;
	import manager.ObjectPool;
	
	import view.base.BaseView;
	import view.base.ClearView;
	import view.bullet.ABullet;
	import view.bullet.BaseBullet;

	public class BulletView extends ClearView
	{
		private var bulletAry:Array;
		
		public function BulletView()
		{
			bulletAry = [];
		}
		
		override public function clearView():void{
			super.clearView();
			bulletAry.length = 0;
		}
		
		override protected function loop(event:Event):void{
			var i:int = 0;
			for(i;i<bulletAry.length;i++){
				var bullet:BaseBullet = bulletAry[i];
				bullet.move();
				bullet.checkHitMonster();
			}
		}
		
		public function createBullet(type:String,p:Point,tar:Point):void{
			var bullet:BaseBullet = ObjectPool.getObj(BulletName.getBulletCls(type)) as BaseBullet;
			bullet.x = p.x;
			bullet.y = p.y;
			bullet.tarPoint = tar;
			bullet.speed = 10;
			bullet.onRemove = removeThis
			this.addChild(bullet);
			bulletAry.push(bullet);
		}
		
		private function removeThis(bullet:BaseBullet):void
		{
			var index:int = bulletAry.indexOf(bullet);
			bulletAry.splice(index,1);
		}
	}
}